import "antd/lib/popover/style/css";
import _Popover from "antd/lib/popover";
import "antd/lib/dropdown/style/css";
import _Dropdown from "antd/lib/dropdown";
import "antd/lib/menu/style/css";
import _Menu from "antd/lib/menu";
import "antd/lib/table/style/css";
import _Table from "antd/lib/table";
import "antd/lib/tooltip/style/css";
import _Tooltip from "antd/lib/tooltip";
import "antd/lib/popconfirm/style/css";
import _Popconfirm from "antd/lib/popconfirm";
import "antd/lib/checkbox/style/css";
import _Checkbox from "antd/lib/checkbox";
import "antd/lib/row/style/css";
import _Row from "antd/lib/row";
import "antd/lib/col/style/css";
import _Col from "antd/lib/col";
import "antd/lib/message/style/css";
import _message from "antd/lib/message";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import React from 'react';
import PropTypes from 'prop-types';
// import { connect } from 'umi';
import { ColumnHeightOutlined, FullscreenOutlined, FullscreenExitOutlined, ReloadOutlined, SettingOutlined // PushpinOutlined,
// VerticalAlignMiddleOutlined,
// PushpinOutlined,
// FilterOutlined,
} from '@ant-design/icons';
import { Resizable } from 'react-resizable';
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
import localStorage from '../utils/localStorage';
import EventsBus from '../utils/events';
import connect from '../context/connect';

var save = function save(nextColumns) {
  var path = window.location.pathname;
  var saveId = "set1".concat(localStorage.getItem('userId')).concat(path.replace(/\//g, '-'));
  var preList = JSON.parse(localStorage.getItem(saveId)) || [];
  var nextMap = {};
  nextColumns.forEach(function (i) {
    nextMap[i.dataIndex] = i.width;
  });
  preList = preList.map(function (i) {
    return _objectSpread(_objectSpread({}, i), {}, {
      width: nextMap[i.dataIndex]
    });
  });
  localStorage.setItem(saveId, JSON.stringify(preList));
};

var ResizeableTitle = function ResizeableTitle(props) {
  var onResize = props.onResize,
      restProps = _objectWithoutProperties(props, ["onResize"]);

  var width = props.width;

  if (!width) {
    return /*#__PURE__*/React.createElement("th", restProps);
  }

  if (props.children && props.children.length > 0 && props.children.indexOf('操作') > -1) {
    return /*#__PURE__*/React.createElement("th", restProps);
  }

  return /*#__PURE__*/React.createElement(Resizable, {
    width: width,
    height: 0,
    onResize: onResize,
    handle: /*#__PURE__*/React.createElement("span", {
      className: "react-resizable-handle",
      onClick: function onClick(e) {
        e.stopPropagation();
      }
    }),
    draggableOpts: {
      enableUserSelectHack: false
    }
  }, /*#__PURE__*/React.createElement("th", restProps));
};

var FlexibleTable = /*#__PURE__*/function (_React$PureComponent) {
  _inherits(FlexibleTable, _React$PureComponent);

  var _super = _createSuper(FlexibleTable);

  function FlexibleTable(_props) {
    var _this;

    _classCallCheck(this, FlexibleTable);

    _this = _super.call(this, _props);
    _this.components = {
      header: {
        cell: ResizeableTitle
      }
    };

    _this.defaultPageSize = function () {
      var state = _this.state;
      var props = _this.props;
      var page = props.page || props.type; // const paginationStr = props.refreshPagination || 'pagination';

      var path = window.location.pathname;

      if (page) {
        // todo 需要规范储存名称 `table${localStorage.getItem('userId')}${path.replace(/\//g, '-')}`;
        var sizeId = state.tableId || "table".concat(localStorage.getItem('userId')).concat(path.replace(/\//g, '-')); // const pagination = props.modelState[page][paginationStr];

        try {
          var tableStr = localStorage.getItem(sizeId);
          var tableCon = JSON.parse(tableStr) || [];
          var pageSize = tableCon[0] || 20;
          var columnHeight = tableCon[1] || props.size || 'middle';

          if (props.setPagination) {
            if (props.setPagination.current) {
              props.setPagination.current.pageSize = Number(pageSize);
            }
          }

          if (columnHeight !== props.size) {
            _this.setState({
              columnHeight: columnHeight
            });
          }
        } catch (e) {
          _message.error("\u6570\u636E\u51FA\u9519\u4E86,{".concat(e, "}\u5237\u65B0\u8BD5\u8BD5")); // eslint-disable-next-line


          console.log(e);
        }
      }
    };

    _this.defaultLocalColumns = function () {
      // 进入页面初始化 进行默认更新保存
      var state = _this.state;
      var props = _this.props;
      var columns = props.columns || [];
      var path = window.location.pathname; // todo 命名不规范 不统一 重复代码

      var pathId = state.columnsId || "set1".concat(localStorage.getItem('userId')).concat(path.replace(/\//g, '-'));
      var localColumnsStr = localStorage.getItem(pathId); // 获取各数组

      var columnsTitleArray = columns.map(function (item) {
        return item.title;
      });
      var localColumnsArray = localColumnsStr && JSON.parse(localColumnsStr) || [];
      var localTitleArray = localColumnsArray.map(function (item) {
        return item.title;
      });
      var columnsList = []; // todo 这段比较逻辑为 待优化代码
      // 第一次循环，取保存数据，判断删除数据

      localColumnsArray.forEach(function (item) {
        var index = columnsTitleArray.indexOf(item.title);
        var columnsItem = columns[index];
        var show = [false, true, undefined].indexOf(item.show);

        if (index !== -1) {
          columnsList.push(_objectSpread(_objectSpread({}, columnsItem), {}, {
            show: !!show,
            width: Number(String(item.width).replace('px', '')) || 0,
            fixed: item.fixed
          }));
        }
      }); // 第二次循环，判断新增数据

      columns.forEach(function (item, i) {
        var index = localTitleArray.indexOf(item.title);

        if (index === -1) {
          var itemQuery = {
            show: true,
            width: Number(String(item.width).replace('px', '')) || 0,
            title: item.title,
            fixed: item.fixed,
            disabled: item.disabled
          };

          if (!item.width) {
            itemQuery.width = 0;
          } else if (!isFinite(item.width)) {
            itemQuery.width = Number(String(item.width).replace('px', '')) || 0;
          }

          if (['操作'].includes(item.title) || !item.dataIndex) {
            itemQuery.width = Number(String(item.width).replace('px', '')) || 0;
            itemQuery.show = true;
            itemQuery.disabled = true;
          } // 插入


          if (i > columnsList.length) {
            columnsList.push(_objectSpread(_objectSpread({}, item), itemQuery));
          } else {
            columnsList.splice(i, 0, _objectSpread(_objectSpread({}, item), itemQuery));
          }
        }
      });
      var column = columnsList.map(function (i) {
        var item = i;

        if (!item.width) {
          item.width = 150;
        }

        return item;
      }).filter(function (item) {
        return item.show;
      }); // 判断if需要浮动(显示6 个以下)

      if (column.length <= 6) {
        for (var i = 0; i < column.length; i += 1) {
          column[i].fixed = null;
        }
      } else {// const columnRight = column.filter(item => item.fixed === 'right');
        // for (let i = 0; i < column.length; i += 1) {
        //   if (column[i].title === '操作' && !column[i].fixed) {
        //     column[i].fixed = 'right';
        //   }
        //   if (i > column.length - columnRight.length) {
        //     if (!column[i].fixed) {
        //       // 去掉几个宽度以自适应
        //       column[i].width = null;
        //     }
        //   }
        // }
      } // 是否为全选


      var checkedAll = true;

      if (column.length !== columnsList.length) {
        checkedAll = false;
      }

      _this.setState({
        checkedAll: checkedAll,
        columns: _toConsumableArray(column),
        columnsLocal: [].concat(columnsList)
      }, function () {
        var columnStr = JSON.stringify(columnsList);
        localStorage.setItem(pathId, columnStr);
      });
    };

    _this.defaultLocalFilter = function () {
      var state = _this.state;
      var path = window.location.pathname;
      var filterId = state.filterId || "setFilter".concat(localStorage.getItem('userId')).concat(path.replace(/\//g, '-'));
      var filterLocalStr = localStorage.getItem(filterId);
      var filterLocalArr = filterLocalStr && JSON.parse(filterLocalStr) || [];

      _this.setState({
        filterLocal: _toConsumableArray(filterLocalArr)
      });
    };

    _this.tableFixedScrollOnChange = function () {
      var tableId = _this.state.tableId;
      var classArr = {
        ts: ".tableNormal".concat(tableId, " .ant-table-content"),
        // table滚动条(当前)
        fs: ".tableFixed".concat(tableId, " .ant-table-content") // 头部滚动条（当前）

      };
      var tableScroll = document.querySelector(classArr.ts);
      var tableFixedScroll = document.querySelector(classArr.fs);
      tableScroll.scrollTo(tableFixedScroll.scrollLeft, 0);
    };

    _this.scrollOnTableFixed = function () {
      var state = _this.state;
      var props = _this.props;
      var settings = props.settings;
      var classArr = {
        w: '.ant-spin-nested-loading',
        c: '.table-container-fixed',
        // 整个table组件包裹层
        t: '.tableNormal .ant-table-content',
        // table滚动条
        f: '.tableFixed .ant-table-content',
        // 头部滚动条
        ts: ".tableNormal".concat(state.tableId, " .ant-table-content"),
        // table滚动条(当前)
        fs: ".tableFixed".concat(state.tableId, " .ant-table-content") // 头部滚动条（当前）

      };
      var top = state.fixedTop || 48;
      var domC = document.querySelector(classArr.c);
      var tableNormal = document.querySelector(classArr.t);
      var tableScroll = document.querySelector(classArr.ts); // 表格头部浮起来

      if (domC && tableScroll.getBoundingClientRect().top <= top && !state.fixed) {
        var fixedStyle = {
          position: 'fixed',
          zIndex: 11,
          background: '#f0f2f5',
          width: domC.clientWidth,
          transition: 'all 0.2s ease-in',
          top: settings.hiddenHeader ? top : top
        }; // fixed 判断是否 固定header

        _this.setState({
          fixed: true,
          fixedStyle: fixedStyle
        }, function () {
          try {
            var tableFixed = document.querySelector(classArr.fs);
            domC.scrollTo(0, 1);

            if (tableFixed) {
              tableFixed.scrollTo(tableNormal.scrollLeft, 10);
            } // 双向监听


            if (tableScroll) {
              tableScroll.addEventListener('scroll', _this.scrollOnTableFixed);
            } // 双向监听


            if (tableFixed) {
              tableFixed.addEventListener('scroll', _this.tableFixedScrollOnChange);
            }
          } catch (e) {
            console.log(e);
          }
        });
      } // 表格头部浮下去


      if (state.fixed) {
        try {
          var tableFixedScroll = document.querySelector(classArr.fs);

          if (tableScroll && tableFixedScroll) {
            tableFixedScroll.scrollTo(tableScroll.scrollLeft, 0);
          }

          if (domC && tableScroll.getBoundingClientRect().top >= top) {
            _this.setState({
              fixed: false
            });
          }
        } catch (e) {
          // eslint-disable-next-line
          console.log(e);
        }
      }
    };

    _this.scrollOnTableResize = function () {
      var state = _this.state;
      var props = _this.props;

      if (state.fixed) {
        // 表头状态
        var style = state.fixedStyle;
        var domW = document.querySelector('.table-container-fixed');

        var fixedStyle = _objectSpread(_objectSpread({}, style), {}, {
          width: domW.clientWidth
        });

        _this.setState({
          fixedStyle: fixedStyle
        });
      }

      var global = props.settings; // chrome 浏览器
      // const isBoolen0 = [false,true,null,undefined].indexOf(document.webkitIsFullScreen)
      // 判断全屏

      var isHeight = Math.abs(document.documentElement.clientHeight - window.screen.height);
      var isFull0 = document.fullscreenElement || document.isFullScreen || document.webkitIsFullScreen;
      var isFull1 = document.documentElement.clientHeight >= window.screen.height;
      var isFull2 = !(state.isFull && Math.abs(isHeight - state.isFull) > 120);

      if ((isFull0 || isFull1) && isFull2) {
        _this.setState({
          isFull: isHeight,
          isFullScreen: true
        }); // if (global.sider && global.sider.includes('top')) {
        //   // deHeader.style.top = 0
        //   props.dispatch({
        //     type: 'global/updateState',
        //     payload: {
        //       preCollapsed: global.collapsed,
        //       collapsed: false,
        //     },
        //   });
        // } else {
        //   // deHeader.style.top = '-45px'
        //   props.dispatch({
        //     type: 'global/updateState',
        //     payload: {
        //       preCollapsed: global.collapsed,
        //       collapsed: true,
        //     },
        //   });
        // }

      } else if (global.hiddenHeader) {
        _this.setState({
          isFullScreen: false
        }); // deHeader.style.top = 0


        _this.setState({
          isFullScreen: false
        }); // props.dispatch({
        //   type: 'global/updateState',
        //   payload: {
        //     collapsed: global.preCollapsed,
        //   },
        // });

      } else if (state.isFullScreen) {
        _this.setState({
          isFullScreen: false
        });
      }
    };

    _this.updateLocalColumns = function () {
      var state = _this.state;
      var path = window.location.pathname;
      var columnsLocal = [];

      if (Array.isArray(state.columnsLocal)) {
        state.columnsLocal.forEach(function (item) {
          var show = [false, true, undefined].indexOf(item.show);

          var itemQ = _objectSpread({}, item);

          itemQ.width = Number(String(item.width).replace('px', '')) || 0;
          itemQ.show = !!show;
          columnsLocal.push(itemQ);
        });
      }

      var columns = columnsLocal.filter(function (item) {
        return item.show;
      });

      if (columns.length <= 6) {
        for (var i = 0; i < columns.length; i += 1) {
          columns[i].fixed = null;
        }
      }

      _this.setState({
        columns: columns
      }, function () {
        var columnsId = state.columnsId || "set1".concat(localStorage.getItem('userId')).concat(path.replace(/\//g, '-'));
        var columnsLocalStr = JSON.stringify(columnsLocal);
        localStorage.setItem(columnsId, columnsLocalStr);
      });
    };

    _this.updateLocalFilter = function () {
      var state = _this.state;
      var path = window.location.pathname;
      var filterLocal = state.filterLocal;

      try {
        var filterId = state.filterId || "setFilter".concat(localStorage.getItem('userId')).concat(path.replace(/\//g, '-'));
        var filterLocalStr = JSON.stringify(filterLocal);
        localStorage.setItem(filterId, filterLocalStr);
        EventsBus.emit("".concat(path, "=refresh"), filterLocal);

        _this.defaultLocalFilter();
      } catch (e) {
        console.log(e);
      }
    };

    _this.handleResize = function (index) {
      return function (e, _ref) {
        var size = _ref.size;

        _this.setState(function (_ref2) {
          var columns = _ref2.columns,
              columnsLocal = _ref2.columnsLocal;

          var nextColumns = _toConsumableArray(columns);

          var nextLocal = _toConsumableArray(columnsLocal);

          nextColumns[index] = _objectSpread(_objectSpread({}, nextColumns[index]), {}, {
            width: size.width
          });
          nextLocal.forEach(function (item, i) {
            var itemTitle = item.title === nextColumns[index].title;
            var dataIndex = item.dataIndex === nextColumns[index].dataIndex;

            if (dataIndex || itemTitle) {
              nextLocal[i] = _objectSpread(_objectSpread({}, columnsLocal[i]), {}, {
                width: size.width
              });
            }
          });
          save(nextColumns);
          return {
            columns: nextColumns,
            columnsLocal: nextLocal
          };
        });
      };
    };

    _this.onPageChangeHeader = function (page, filters, sort) {
      var pagination = _this.props.pagination;
      var state = _this.state;
      var sorter = sort || state.sorter;

      _this.onPageChange(pagination, filters, sorter);

      _this.setState({
        sorter: sorter
      });
    };

    _this.onPageChange = function (page, filters, sort) {
      var state = _this.state;
      var sorter = sort || state.sorter; // 保存一份排序数据，防止 onPageChange在独立调用的时候，没有sorter数据

      _this.setState({
        sorter: sorter
      });

      var onChange = _this.props.onChange;
      var path = window.location.pathname;
      var pageSizeId = state.pageSizeId || "table".concat(localStorage.getItem('userId')).concat(path.replace(/\//g, '-'));

      if (onChange && page) {
        var tableCon = [page.pageSize, state.columnHeight];
        var tableStr = JSON.stringify(tableCon);
        localStorage.setItem(pageSizeId, tableStr);
        onChange(page, filters, sorter);
      } else if (onChange && !page) {
        // 没有分页的情况
        onChange({}, filters, sorter);
      }
    };

    _this.columnHeightChange = function (target) {
      var props = _this.props;

      var callback = function callback() {
        return _this.onPageChange(props.pagination);
      };

      _this.setState({
        columnHeight: target.key
      }, callback);
    };

    _this.tableFullScreen = function () {
      // const state = this.state
      var de = document.documentElement;
      var fullScreen = document.isFullScreen || document.mozIsFullScreen || document.webkitIsFullScreen;

      if (!de) {
        return;
      }

      if (!fullScreen) {
        if (de.requestFullscreen) {
          de.requestFullscreen();
        } else if (de.mozRequestFullScreen) {
          de.mozRequestFullScreen();
        } else if (de.webkitRequestFullScreen) {
          de.webkitRequestFullScreen();
        }
      }

      if (fullScreen) {
        if (document.exitFullscreen) {
          if (document.isFullScreen || document.mozIsFullScreen || document.webkitIsFullScreen) {
            document.exitFullscreen();
          } else {
            // F11 全屏API  HTML5 无法调用
            _message.error('请按键盘 F11 退出全屏');
          }
        } else if (document.mozCancelFullScreen) {
          document.mozCancelFullScreen();
        } else if (document.webkitCancelFullScreen) {
          document.webkitCancelFullScreen();
        }
      }
    };

    _this.tableFixedChange = function (event, i) {
      var state = _this.state;
      var props = _this.props;

      var columnsLocal = _toConsumableArray(state.columnsLocal);

      var leftFixed = columnsLocal.filter(function (item) {
        return item.fixed === 'left';
      });
      var rightFixed = columnsLocal.filter(function (item) {
        return item.fixed === 'right';
      });

      if (props.disabled) {
        _message.error('该表格不允许浮动固定');

        return;
      } // 判断最多固定 6 个


      if (!event.fixed && leftFixed.length + rightFixed.length >= 6 && i) {
        _message.error('超过固定最大值');

        return;
      }

      if (!i && event.title === '操作') {
        _message.error('操作按钮不能取消');

        return;
      }

      if (i && event.disabled) {
        _message.error('该钮不允许操作');

        return;
      }

      state.columnsLocal.forEach(function (item, j) {
        // dataIndex 或者 title 判断元素
        if (item.dataIndex === event.dataIndex || item.title === event.title) {
          if (i === -1) {
            // 左固定
            var _columnsLocal$splice = columnsLocal.splice(j, 1),
                _columnsLocal$splice2 = _slicedToArray(_columnsLocal$splice, 1),
                columnsItem = _columnsLocal$splice2[0];

            columnsItem.fixed = 'left';
            columnsLocal.splice(leftFixed.length, 0, columnsItem);
          }

          if (i === 0) {
            // 取消
            var _columnsLocal$splice3 = columnsLocal.splice(j, 1),
                _columnsLocal$splice4 = _slicedToArray(_columnsLocal$splice3, 1),
                _columnsItem = _columnsLocal$splice4[0];

            if (item.fixed === 'left') {
              _columnsItem.fixed = null;
              columnsLocal.splice(leftFixed.length - 1, 0, _columnsItem);
            }

            if (item.fixed === 'right') {
              _columnsItem.fixed = null;
              columnsLocal.splice(columnsLocal.length - rightFixed.length + 1, 0, _columnsItem);
            }
          }

          if (i === 1) {
            // 右固定
            var _columnsLocal$splice5 = columnsLocal.splice(j, 1),
                _columnsLocal$splice6 = _slicedToArray(_columnsLocal$splice5, 1),
                _columnsItem2 = _columnsLocal$splice6[0];

            _columnsItem2.fixed = 'right';
            columnsLocal.splice(columnsLocal.length - rightFixed.length, 0, _columnsItem2);
          }
        }
      });

      _this.setState({
        columnsLocal: columnsLocal
      }, _this.updateLocalColumns);
    };

    _this.pageReLoad = function () {
      var pagination = _this.props.pagination;

      _this.onPageChange(pagination);
    };

    _this.onTableDragEnd = function (result) {
      var state = _this.state;
      var props = _this.props;

      if (props.disabled) {
        _message.error('该表格不允许拖拽排序');

        return;
      }

      if (!result.destination) {
        return;
      }

      var columnsLocal = _this.reorder(state.columnsLocal, result.source.index, result.destination.index);

      var columns = columnsLocal.filter(function (item) {
        return item.show;
      });

      _this.setState({
        columnsLocal: columnsLocal,
        columns: _toConsumableArray(columns)
      }, _this.updateLocalColumns);
    };

    _this.onTableDragLeftEnd = function (result) {
      var state = _this.state;
      var props = _this.props;

      if (props.disabled) {
        _message.error('该表格不允许拖拽排序');

        return;
      }

      if (!result.destination) {
        return;
      }

      var columnsLocal = state.columnsLocal;
      var columnsLeft = state.columnsLocal.filter(function (item) {
        return item.fixed === 'left';
      });

      var columnsLocalLeft = _this.reorderLeft(columnsLeft, result.source.index, result.destination.index);

      columnsLocal.splice.apply(columnsLocal, [0, columnsLeft.length].concat(_toConsumableArray(columnsLocalLeft)));
      var columns = columnsLocal.filter(function (item) {
        return item.show;
      });

      _this.setState({
        columnsLocal: columnsLocal,
        columns: _toConsumableArray(columns)
      }, _this.updateLocalColumns);
    };

    _this.onTableDragRightEnd = function (result) {
      var state = _this.state;
      var props = _this.props;

      if (props.disabled) {
        _message.error('该表格不允许拖拽排序');

        return;
      }

      if (!result.destination) {
        return;
      }

      var columnsLocal = state.columnsLocal;
      var columnsRight = state.columnsLocal.filter(function (item) {
        return item.fixed === 'right';
      });

      var columnsLocalRight = _this.reorderLeft(columnsRight, result.source.index, result.destination.index);

      columnsLocal.splice.apply(columnsLocal, [columnsLocal.length - columnsRight.length, columnsRight.length].concat(_toConsumableArray(columnsLocalRight)));
      var columns = columnsLocal.filter(function (item) {
        return item.show;
      });

      _this.setState({
        columnsLocal: columnsLocal,
        columns: _toConsumableArray(columns)
      }, _this.updateLocalColumns);
    };

    _this.onFilterDragEnd = function (result) {
      var state = _this.state;

      if (!result.destination) {
        return;
      }

      var filterLocal = _this.reorder(state.filterLocal, result.source.index, result.destination.index);

      _this.setState({
        filterLocal: _toConsumableArray(filterLocal)
      }, _this.updateLocalFilter);
    };

    _this.reorder = function (list, startIndex, endIndex) {
      var result = Array.from(list);
      var left = result.filter(function (item) {
        return item.fixed === 'left';
      });
      var startI = startIndex + left.length;
      var index = endIndex + left.length;

      var _result$splice = result.splice(startI, 1),
          _result$splice2 = _slicedToArray(_result$splice, 1),
          removed = _result$splice2[0];

      var lastItem = result[index - 1] || {};

      if (lastItem.title !== '操作' && !lastItem.disabled) {
        result.splice(index, 0, removed);
        return result;
      } else {
        return list;
      }
    };

    _this.reorderLeft = function (list, startIndex, endIndex) {
      var result = Array.from(list);

      var _result$splice3 = result.splice(startIndex, 1),
          _result$splice4 = _slicedToArray(_result$splice3, 1),
          removed = _result$splice4[0];

      var lastItem = result[endIndex - 1] || {};

      if (lastItem.title !== '操作' && !lastItem.disabled) {
        result.splice(endIndex, 0, removed);
        return result;
      } else {
        return list;
      }
    };

    _this.getListStyle = function () {
      return {
        background: '#fff',
        width: 'auto'
      };
    };

    _this.getItemStyle = function (isDragging, draggableStyle) {
      return _objectSpread({
        userSelect: 'none',
        padding: '8px 16px',
        background: isDragging ? '#fafafa' : '#fff',
        // borderBottom: '1px solid #f0f0f0',
        translation: 'background 0.1s'
      }, draggableStyle);
    };

    _this.columnsOnCheck = function (e) {
      var state = _this.state;
      var columnsLocal = state.columnsLocal;
      var name = e.target.value;
      var value = e.target.checked; // 过滤操作按钮

      if (!name || name === '操作') {
        return;
      }

      columnsLocal.forEach(function (item, i) {
        if ([item.dataIndex, item.title].includes(name)) {
          columnsLocal[i].show = value;
        }
      });

      _this.setState({
        columnsLocal: columnsLocal
      }, _this.updateLocalColumns);
    };

    _this.filterOnCheck = function (e) {
      var state = _this.state;
      var filterLocal = state.filterLocal;
      var name = e.target.value;
      var value = e.target.checked; // 过滤操作按钮

      if (!name) {
        return;
      }

      filterLocal.forEach(function (item, i) {
        if ([item.value, item.label].includes(name)) {
          filterLocal[i].show = value;
        }
      });

      _this.setState({
        filterLocal: filterLocal
      }, _this.updateLocalFilter);
    };

    _this.columnsOnCheckAll = function () {
      var state = _this.state;
      var checkout = state.checkout;

      if (checkout === 'table') {
        var columnsLocal = state.columnsLocal;
        var tableCheckedAll = !state.tableCheckedAll;
        columnsLocal.forEach(function (item, i) {
          if (item.title !== '操作') {
            columnsLocal[i].show = tableCheckedAll;
          }
        });

        _this.setState({
          columnsLocal: columnsLocal,
          tableCheckedAll: tableCheckedAll
        }, _this.updateLocalColumns);
      }

      if (checkout === 'filter') {
        var filterLocal = state.filterLocal;
        var filterCheckedAll = !state.filterCheckedAll;
        filterLocal.forEach(function (item, i) {
          if (item.title !== '操作') {
            filterLocal[i].show = filterCheckedAll;
          }
        });

        _this.setState({
          filterLocal: filterLocal,
          filterCheckedAll: filterCheckedAll
        }, _this.updateLocalFilter);
      }
    };

    _this.isSelectAll = function (name) {
      var _this$state = _this.state,
          columnsLocal = _this$state.columnsLocal,
          filterLocal = _this$state.filterLocal;
      var tableSelectedLength = 0;
      var filterSelectedLength = 0;

      if (name === 'filter') {
        filterLocal.forEach(function (item) {
          if (item.show) {
            filterSelectedLength += 1;
          }
        });

        if (filterSelectedLength === filterLocal.length) {
          return false;
        }

        return true;
      }

      if (name === 'table') {
        columnsLocal.forEach(function (item) {
          if (item.show) {
            tableSelectedLength += 1;
          }
        });

        if (tableSelectedLength === columnsLocal.length) {
          return false;
        }

        return true;
      }
    };

    _this.resetFilterColumns = function () {
      var state = _this.state;
      var path = window.location.pathname;
      var tableId = state.tableId || "table".concat(localStorage.getItem('userId')).concat(path.replace(/\//g, '-'));
      var columnsId = state.columnsId || "set1".concat(localStorage.getItem('userId')).concat(path.replace(/\//g, '-'));
      var filterId = state.filterId || "setFilter".concat(localStorage.getItem('userId')).concat(path.replace(/\//g, '-'));

      if (state.checkout === 'filter') {
        //  触发事件
        localStorage.removeItem(filterId);
        EventsBus.emit("".concat(path, "=refresh"), null);

        _this.defaultLocalFilter();

        return;
      }

      try {
        localStorage.removeItem(tableId);
        localStorage.removeItem(columnsId);

        _this.defaultPageSize();

        _this.defaultLocalColumns();
      } catch (e) {
        console.log('可能不支持 localStorage', e);
      }
    };

    _this.popconfirmRender = function (name) {
      var state = _this.state;
      var _this$props$columnsFi = _this.props.columnsFilter,
          columnsFilter = _this$props$columnsFi === void 0 ? [] : _this$props$columnsFi;

      if (name === 'title') {
        var rowStyle = {
          height: 32,
          lineHeight: '32px',
          fontSize: 14,
          paddingLeft: 16,
          paddingRight: 16,
          color: 'rgba(0,0,0,0.6)'
        };
        var setStyle = {
          fontSize: 16,
          paddingTop: 8,
          paddingBottom: 8,
          marginBottom: 8,
          marginTop: -8,
          color: 'rgba(0,0,0,0.6)',
          backgroundColor: '#fafafa'
        };
        var titleObj = {
          table: '表格展示',
          filter: '查询展示'
        };

        var checkoutFilter = function checkoutFilter() {
          _this.setState({
            checkout: 'filter'
          });
        };

        var checkoutTable = function checkoutTable() {
          _this.setState({
            checkout: 'table'
          });
        };

        return /*#__PURE__*/React.createElement("div", null, columnsFilter.length === 0 ? /*#__PURE__*/React.createElement(_Row, {
          gutter: 32,
          style: setStyle
        }, /*#__PURE__*/React.createElement(_Col, {
          span: 24,
          align: "left",
          className: "title",
          style: {
            paddingLeft: 30
          } // onClick={checkoutTable}

        }, "\u8868\u683C\u8BBE\u7F6E")) : /*#__PURE__*/React.createElement(_Row, {
          gutter: 32,
          style: setStyle
        }, /*#__PURE__*/React.createElement(_Col, {
          span: 12,
          align: "center",
          className: "title",
          action: state.checkout === 'filter' ? 'active' : 0,
          style: {
            cursor: 'pointer'
          },
          onClick: checkoutFilter
        }, "\u67E5\u8BE2\u8BBE\u7F6E"), /*#__PURE__*/React.createElement(_Col, {
          span: 12,
          align: "center",
          className: "title",
          action: state.checkout === 'table' ? 'active' : 0,
          style: {
            cursor: 'pointer'
          },
          onClick: checkoutTable
        }, "\u8868\u683C\u8BBE\u7F6E")), /*#__PURE__*/React.createElement(_Row, {
          style: rowStyle
        }, /*#__PURE__*/React.createElement(_Col, {
          span: 4
        }, /*#__PURE__*/React.createElement(_Checkbox, {
          indeterminate: _this.isSelectAll(state.checkout),
          checked: state.checkedAll,
          onChange: _this.columnsOnCheckAll
        })), /*#__PURE__*/React.createElement(_Col, {
          span: 16,
          align: "left"
        }, titleObj[state.checkout]), /*#__PURE__*/React.createElement(_Col, {
          span: 4
        }, /*#__PURE__*/React.createElement(_Popconfirm, {
          title: "\u786E\u5B9A\u91CD\u7F6E\u5417?",
          onConfirm: _this.resetFilterColumns
        }, /*#__PURE__*/React.createElement("a", null, "\u91CD\u7F6E")))));
      }

      if (name === 'main') {
        return _this.checkoutRender(state.checkout);
      }
    };

    _this.checkoutRender = function (name) {
      var state = _this.state;

      if (name === 'table') {
        var fixedLeftArray = state.columnsLocal.filter(function (item) {
          return item.fixed === 'left';
        });
        var fixedRightArray = state.columnsLocal.filter(function (item) {
          return item.fixed === 'right';
        });
        var fixedNullArray = state.columnsLocal.filter(function (item) {
          return !item.fixed;
        });
        var fixedNullHeight = fixedNullArray.length < 9 ? fixedNullArray.length * 40 : 360;
        var fixedLeftHeight = fixedLeftArray.length < 9 ? fixedLeftArray.length * 40 : 360;
        var fixedRightHeight = fixedRightArray.length < 9 ? fixedRightArray.length * 40 : 360;
        return /*#__PURE__*/React.createElement("div", {
          style: {
            width: 250
          }
        }, /*#__PURE__*/React.createElement("div", {
          style: {
            fontSize: 12,
            paddingLeft: 16,
            color: '#8c8c8c'
          }
        }, !!fixedLeftArray.length && '固定左侧'), /*#__PURE__*/React.createElement(DragDropContext, {
          onDragEnd: _this.onTableDragLeftEnd
        }, /*#__PURE__*/React.createElement("div", {
          style: {
            height: fixedLeftHeight,
            overflow: 'auto'
          }
        }, /*#__PURE__*/React.createElement(Droppable, {
          droppableId: "fixedLeftdroppable"
        }, function (provided, snapshot) {
          return /*#__PURE__*/React.createElement("div", _extends({}, provided.droppableProps, {
            ref: provided.innerRef,
            style: _this.getListStyle(snapshot)
          }), fixedLeftArray.map(function (item, index) {
            return /*#__PURE__*/React.createElement(Draggable, {
              index: index,
              key: item.title,
              draggableId: item.title,
              isDragDisabled: item.title === '操作' || item.disabled
            }, function (provided2, snapshot2) {
              return /*#__PURE__*/React.createElement("div", _extends({}, provided2.draggableProps, provided2.dragHandleProps, {
                ref: provided2.innerRef,
                style: _this.getItemStyle(snapshot2.isDragging, provided2.draggableProps.style)
              }), /*#__PURE__*/React.createElement(_Row, null, /*#__PURE__*/React.createElement(_Col, {
                span: 4,
                align: "left"
              }, /*#__PURE__*/React.createElement(_Checkbox, {
                checked: item.show,
                onChange: _this.columnsOnCheck,
                value: item.dataIndex || item.title,
                disabled: item.title === '操作' || item.disabled
              })), /*#__PURE__*/React.createElement(_Col, {
                span: 16,
                align: "left"
              }, item.title), /*#__PURE__*/React.createElement(_Col, {
                span: 4
              }, /*#__PURE__*/React.createElement(_Tooltip, {
                title: "\u53D6\u6D88\u56FA\u5B9A"
              }), /*#__PURE__*/React.createElement(_Tooltip, {
                title: "\u56FA\u5B9A\u53F3\u4FA7"
              }))));
            });
          }), provided.placeholder);
        }))), /*#__PURE__*/React.createElement("div", {
          style: {
            fontSize: 12,
            paddingLeft: 16,
            color: '#8c8c8c'
          }
        }, (!!fixedLeftArray.length || !!fixedRightArray.length) && '不固定'), /*#__PURE__*/React.createElement(DragDropContext, {
          onDragEnd: _this.onTableDragEnd
        }, /*#__PURE__*/React.createElement("div", {
          style: {
            height: fixedNullHeight,
            overflow: 'auto'
          }
        }, /*#__PURE__*/React.createElement(Droppable, {
          droppableId: "droppable"
        }, function (provided, snapshot) {
          return /*#__PURE__*/React.createElement("div", _extends({}, provided.droppableProps, {
            ref: provided.innerRef,
            style: _this.getListStyle(snapshot)
          }), fixedNullArray.map(function (item, index) {
            return /*#__PURE__*/React.createElement(Draggable, {
              index: index,
              key: item.title,
              draggableId: item.title,
              isDragDisabled: item.title === '操作' || item.disabled
            }, function (provided2, snapshot2) {
              return /*#__PURE__*/React.createElement("div", _extends({}, provided2.draggableProps, provided2.dragHandleProps, {
                ref: provided2.innerRef,
                style: _this.getItemStyle(snapshot2.isDragging, provided2.draggableProps.style)
              }), /*#__PURE__*/React.createElement(_Row, null, /*#__PURE__*/React.createElement(_Col, {
                span: 4,
                align: "left"
              }, /*#__PURE__*/React.createElement(_Checkbox, {
                checked: item.show,
                onChange: _this.columnsOnCheck,
                value: item.dataIndex || item.title,
                disabled: item.title === '操作' || item.disabled
              })), /*#__PURE__*/React.createElement(_Col, {
                span: 16,
                align: "left"
              }, item.title), /*#__PURE__*/React.createElement(_Col, {
                span: 4
              }, /*#__PURE__*/React.createElement(_Tooltip, {
                title: "\u56FA\u5B9A\u5DE6\u4FA7"
              }), /*#__PURE__*/React.createElement(_Tooltip, {
                title: "\u56FA\u5B9A\u53F3\u4FA7"
              }))));
            });
          }), provided.placeholder);
        }))), /*#__PURE__*/React.createElement("div", {
          style: {
            fontSize: 12,
            paddingLeft: 16,
            color: '#8c8c8c'
          }
        }, !!fixedRightArray.length && '固定右侧'), /*#__PURE__*/React.createElement(DragDropContext, {
          onDragEnd: _this.onTableDragRightEnd
        }, /*#__PURE__*/React.createElement("div", {
          style: {
            height: fixedRightHeight,
            overflow: 'auto'
          }
        }, /*#__PURE__*/React.createElement(Droppable, {
          droppableId: "fixedRightdroppable"
        }, function (provided, snapshot) {
          return /*#__PURE__*/React.createElement("div", _extends({}, provided.droppableProps, {
            ref: provided.innerRef,
            style: _this.getListStyle(snapshot)
          }), fixedRightArray.map(function (item, index) {
            return /*#__PURE__*/React.createElement(Draggable, {
              index: index,
              key: item.title,
              draggableId: item.title,
              isDragDisabled: item.title === '操作' || item.disabled
            }, function (provided2, snapshot2) {
              return /*#__PURE__*/React.createElement("div", _extends({}, provided2.draggableProps, provided2.dragHandleProps, {
                ref: provided2.innerRef,
                style: _this.getItemStyle(snapshot2.isDragging, provided2.draggableProps.style)
              }), /*#__PURE__*/React.createElement(_Row, null, /*#__PURE__*/React.createElement(_Col, {
                span: 4,
                align: "left"
              }, /*#__PURE__*/React.createElement(_Checkbox, {
                checked: item.show,
                onChange: _this.columnsOnCheck,
                value: item.dataIndex || item.title,
                disabled: item.title === '操作' || item.disabled
              })), /*#__PURE__*/React.createElement(_Col, {
                span: 16,
                align: "left"
              }, item.title), /*#__PURE__*/React.createElement(_Col, {
                span: 4
              }, /*#__PURE__*/React.createElement(_Tooltip, {
                title: "\u56FA\u5B9A\u5DE6\u4FA7"
              }), /*#__PURE__*/React.createElement(_Tooltip, {
                title: "\u53D6\u6D88\u56FA\u5B9A"
              }))));
            });
          }), provided.placeholder);
        }))));
      }

      if (name === 'filter') {
        var filterHeight = state.filterLocal.length < 9 ? state.filterLocal.length * 40 : 360;
        return /*#__PURE__*/React.createElement("div", {
          style: {
            width: 250
          }
        }, /*#__PURE__*/React.createElement(DragDropContext, {
          onDragEnd: _this.onFilterDragEnd
        }, /*#__PURE__*/React.createElement("div", {
          style: {
            height: filterHeight,
            overflow: 'auto'
          }
        }, /*#__PURE__*/React.createElement(Droppable, {
          droppableId: "droppable2"
        }, function (provided, snapshot) {
          return /*#__PURE__*/React.createElement("div", _extends({}, provided.droppableProps, {
            ref: provided.innerRef,
            style: _this.getListStyle(snapshot)
          }), state.filterLocal.map(function (item, index) {
            return /*#__PURE__*/React.createElement(Draggable, {
              index: index,
              key: item.label,
              draggableId: item.label
            }, function (provided2, snapshot2) {
              return /*#__PURE__*/React.createElement("div", _extends({}, provided2.draggableProps, provided2.dragHandleProps, {
                ref: provided2.innerRef,
                style: _this.getItemStyle(snapshot2.isDragging, provided2.draggableProps.style)
              }), /*#__PURE__*/React.createElement(_Row, null, /*#__PURE__*/React.createElement(_Col, {
                span: 4,
                align: "left"
              }, /*#__PURE__*/React.createElement(_Checkbox, {
                checked: item.show,
                onChange: _this.filterOnCheck,
                value: item.label
              })), /*#__PURE__*/React.createElement(_Col, {
                span: 20,
                align: "left"
              }, item.label)));
            });
          }), provided.placeholder);
        }))));
      }
    };

    _this.state = {
      columns: [],
      columnsLocal: [],
      filterLocal: [],
      tableId: null,
      filterId: null,
      columnsId: null,
      tableCheckedAll: true,
      filterCheckedAll: true,
      pageSizeId: null,
      checkout: 'table',
      columnHeight: 'middle',
      fixed: false,
      sorter: {},
      // 保存一份排序数据
      fixedTop: 48
    }; // this.i = 0;

    return _this;
  }

  _createClass(FlexibleTable, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      var props = this.props;
      var path = window.location.pathname;
      var tableId = "table".concat(localStorage.getItem('userId')).concat(path.replace(/\//g, '-'));
      var columnsId = "set1".concat(localStorage.getItem('userId')).concat(path.replace(/\//g, '-'));
      var filterId = "setFilter".concat(localStorage.getItem('userId')).concat(path.replace(/\//g, '-'));
      var columnHeight = props.size;
      this.setState({
        tableId: tableId,
        filterId: filterId,
        columnsId: columnsId,
        columnHeight: columnHeight
      });
      this.defaultPageSize();
      this.defaultLocalColumns();
      this.defaultLocalFilter(); // 监听事件
      // window.addEventListenter 监听resize会导致多页面监听事件-事件重复触发
      // 监听是否全屏事件
      // todo dom0级事件会覆盖，不知道吗？

      window.onresize = this.scrollOnTableResize;
      document.addEventListener('scroll', this.scrollOnTableFixed);
    }
  }, {
    key: "componentWillReceiveProps",
    value: function componentWillReceiveProps(nextProps) {
      var props = this.props;
      var state = this.state;

      try {
        var preGlobal = props.settings;
        var nextGlobal = nextProps.settings;
        var style = state.fixedStyle; // 多工作台，对固定表头的影响

        if (nextProps.settings.mutilModel && state.fixedTop !== 88) {
          this.setState({
            fixedTop: 88,
            fixedStyle: _objectSpread(_objectSpread({}, style), {}, {
              top: 88
            })
          });
        }

        if (!nextProps.settings.mutilModel && state.fixedTop !== 48) {
          this.setState({
            fixedTop: 48,
            fixedStyle: _objectSpread(_objectSpread({}, style), {}, {
              top: 48
            })
          });
        } // 判断左侧菜单缩进（左侧菜单对，固定表头的影响）


        if (preGlobal.collapsed !== nextGlobal.collapsed) {
          if (state.fixed) {
            // 判断table 列表fixed
            // const width = nextGlobal.collapsed ? -128 : 128;
            var _style = state.fixedStyle;

            var fixedStyle = _objectSpread(_objectSpread({}, _style), {}, {
              width: 'auto'
            });

            if (nextGlobal.collapsed) {
              fixedStyle.left = 80 + 24 + 24 + 'px';
              fixedStyle.right = 24 + 24 + 'px';
            } else {
              fixedStyle.left = 208 + 24 + 24 + 'px';
              fixedStyle.right = 24 + 24 + 'px';
            }

            this.setState({
              fixedStyle: fixedStyle
            });
          }
        } // 判断 菜单模式改变
        // todo 无效代码
        // 浅比较


        var preArr = state.columns;
        var currArr = nextProps.columns;

        if (!preArr || !currArr) {
          return;
        }

        var preShowArray = preArr.filter(function (item) {
          return item.show;
        });
        var currShowArray = currArr.filter(function (item) {
          return item.show;
        });

        if (preShowArray.length !== currShowArray.length) {
          // 个数更新
          this.defaultLocalColumns();
          return;
        } // todo 冗余代码 后面应该统一（需要简化逻辑，为只要有一个变化，那么就重置）


        for (var i = 0; i < currArr.length; i += 1) {
          // 字段更新
          var curr = currArr[i] || {};
          var pre = preArr[i] || {};

          if (curr.dataIndex !== pre.dataIndex) {
            // 字段名称变换
            this.defaultLocalColumns();
            return;
          }
        }
      } catch (e) {
        // eslint-disable-next-line
        console.log(e);
      }
    }
  }, {
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      var state = this.state;
      window.onresize = null;
      document.removeEventListener('scroll', this.scrollOnTableFixed); // todo  重复代码 .tableNormal${state.tableId} .ant-table-content

      var tableScroll = document.querySelector(".tableNormal".concat(state.tableId, " .ant-table-content"));
      var tableFixed = document.querySelector(".tableFixed".concat(state.tableId, " .ant-table-content"));

      if (tableScroll) {
        tableScroll.removeEventListener('scroll', this.scrollOnTableFixed);
      }

      if (tableFixed) {
        tableFixed.addEventListener('scroll', this.tableFixedScrollOnChange);
      }
    } // 默认设置表格pageSize

  }, {
    key: "render",
    value: function render() {
      var _this2 = this;

      var state = this.state;
      var props = this.props;
      var settings = props.settings; // this.i += 1;
      // console.log(props.page, '表格设置渲染次数：', this.i);

      var width = 0;
      var columns = state.columns.map(function (col, index) {
        width += col.width || 0;
        return _objectSpread(_objectSpread({}, col), {}, {
          sortOrder: state.sorter.columnKey === col.key && state.sorter.order,
          // 排序受控
          onHeaderCell: function onHeaderCell(column) {
            return {
              width: column.width,
              onResize: _this2.handleResize(index)
            };
          }
        });
      });
      width = width > document.body.clientWidth - 100 ? width : undefined;
      return /*#__PURE__*/React.createElement("div", {
        className: "table-container-fixed",
        style: {
          position: 'relative',
          overflow: 'hidden'
        }
      }, !!state.fixed && /*#__PURE__*/React.createElement("div", {
        style: state.fixedStyle,
        className: "fixed-table"
      }, /*#__PURE__*/React.createElement(_Table, {
        columns: columns,
        scroll: {
          x: width
        },
        size: state.columnHeight,
        onChange: this.onPageChange // components={this.components}
        ,
        dataSource: [] // bordered={this.props.bordered}
        ,
        className: ['tableFixed', "tableFixed".concat(state.tableId)]
      })), /*#__PURE__*/React.createElement(React.Fragment, null, props.tableHeader ? props.tableHeader( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Tooltip, {
        title: "\u5BC6\u5EA6"
      }, /*#__PURE__*/React.createElement(_Dropdown, {
        trigger: "click",
        overlay: /*#__PURE__*/React.createElement(_Menu, {
          selectable: true,
          onClick: this.columnHeightChange,
          selectedKeys: [state.columnHeight]
        }, /*#__PURE__*/React.createElement(_Menu.Item, {
          key: "default"
        }, "\u9ED8\u8BA4"), /*#__PURE__*/React.createElement(_Menu.Item, {
          key: "middle"
        }, "\u4E2D\u7B49"), /*#__PURE__*/React.createElement(_Menu.Item, {
          key: "small"
        }, "\u7D27\u51D1"))
      }, /*#__PURE__*/React.createElement(ColumnHeightOutlined, {
        style: {
          fontSize: 16,
          marginLeft: 16
        }
      }))), /*#__PURE__*/React.createElement(_Tooltip, {
        title: state.isFullScreen ? '退出全屏' : '全屏'
      }, state.isFullScreen ? /*#__PURE__*/React.createElement(FullscreenExitOutlined, {
        onClick: this.tableFullScreen,
        style: {
          fontSize: 16,
          marginLeft: 16
        }
      }) : /*#__PURE__*/React.createElement(FullscreenOutlined, {
        onClick: this.tableFullScreen,
        style: {
          fontSize: 16,
          marginLeft: 16
        }
      })), /*#__PURE__*/React.createElement(_Tooltip, {
        title: "\u5237\u65B0"
      }, /*#__PURE__*/React.createElement(ReloadOutlined, {
        style: {
          fontSize: 16,
          marginLeft: 16
        },
        onClick: this.pageReLoad
      })), /*#__PURE__*/React.createElement(_Tooltip, {
        title: "\u8BBE\u7F6E"
      }, /*#__PURE__*/React.createElement(_Popover, {
        trigger: "click" // destroyTooltipOnHide
        // getPopupContainer={()=>document.querySelector('.ant-tabs.ant-tabs-card')}
        ,
        autoAdjustOverflow: false,
        placement: "bottomRight",
        arrowPointAtCenter: true,
        zIndex: 4,
        className: "table-setting",
        title: this.popconfirmRender('title'),
        content: this.popconfirmRender('main')
      }, /*#__PURE__*/React.createElement(SettingOutlined, {
        style: {
          fontSize: 16,
          marginLeft: 16
        }
      }))))) : null, /*#__PURE__*/React.createElement(_Table, _extends({}, this.props, {
        columns: columns // bordered={[3, 4].includes(tableSelected)}
        ,
        scroll: {
          x: width
        },
        size: state.columnHeight,
        components: this.components,
        onChange: this.onPageChange,
        pagination: props.noPagination ? false : props.pagination // style={{ minWidth: '100%' }}
        ,
        dataSource: props.dataSource || [],
        className: ['tableNormal', "tableNormal".concat(state.tableId), "tableModal-".concat(settings.tableLayout), state.fixed && 'noScroll'],
        bordered: ['verticalLine', 'zebraVerticalLine'].includes(settings.tableLayout)
      }))));
    }
  }]);

  return FlexibleTable;
}(React.PureComponent);

FlexibleTable.defaultProps = {
  settings: {}
}; // 监听这些数据的变化 ['mutilModel','collapsed'] todo 这些数据如果有变化，组件就会获取新的 setting

export default connect(['mutilModel', 'collapsed', 'tableLayout'])(React.memo(FlexibleTable));